﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI.WebControls;
using Framework.Library.Base.Base;
using Framework.Library.Base.Extensions;
using Framework.Library.Core.Utils;
using Framework.Library.Data.DAL;
using Framework.Library.Data.DAL.JObject;
using Framework.Library.Data.DAO;
using ServiceStack.Text;
using Framework.Library.Core.Utils.GlobalHelper;
using Framework.Library.Core.Config;

namespace Framework.Portal.Layouts.Client.Components.Teenio
{
    public partial class Diary : BaseControl
    {
        public string MENUNAME = string.Empty;

        public Diary()
        {
        }

        public Diary(JSection section)
        {
            MENUNAME = section.title;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<TeenioPayment> lst = ManagerFactory.DAOEntity.GetList(new TeenioPayment() { PaygateID = Convert.ToInt32(currentUserId) });
                if (lst.Count > 0)
                {
                    rptContent.DataSource = lst;
                    rptContent.DataBind();
                }
            }
        }

        protected void rptContent_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var info = (TeenioPayment)e.Item.DataItem;
                var lblCreatedate = (Literal)e.Item.FindControl("lblCreatedate");
                var lblDescription = (Literal)e.Item.FindControl("lblDescription");
                var lblPrice = (Literal)e.Item.FindControl("lblPrice");
                var lblStatus = (Literal)e.Item.FindControl("lblStatus");
                var btnCancel = (ImageButton)e.Item.FindControl("btnCancel");

                lblCreatedate.Text = DateTimeHelper.formatDateTime(info.LastUpdateTime);
                lblDescription.Text = info.Description;
                lblPrice.Text = info.Amount.ToString();
                lblStatus.Text = StaticData.PaymentType[Convert.ToInt32(info.Status)];
                if (info.Status != 0)
                    btnCancel.Visible = false;
            }
        }
    }
}